<?php

class PersonAction extends CommonAction {
    
    public function _empty() {
        $tpl = "../Include/App/Group/Bridge/Tpl/Public_404.html";
        $this->display($tpl);
    }

    protected function sidebarData($uid) {
        $arr = M('user_info')->field('xia_user_info.*, xia_dic.name as goodat')->where("xia_user_info.uid ='" . $uid . "'")->join("xia_dic ON xia_user_info.shanchang=xia_dic.id")->find();
        //数据过滤
        if ($arr['mobile'] > 0) {
            if (
                    //$this->userinfo['utype'] == 2 //企业用户也不能看到，为vip设计预留
                    (($this->userinfo['teamid'] > 0) && $this->userinfo['teamid'] == $arr['teamid']) //在同一个团队
            )
            {
            }
            else{
                $arr['mobile'] = hidetel($arr['mobile']); //对号码加星号处理
            }
        }
        //隐私过滤
        $this->priArr = userInfoFilter($this->userinfo, $arr);
        $arr['nickname'] = convEmail($arr['nickname']);
        
        $this->assign("theirinfo", $arr); //用户信息
        
        //抛橄榄枝数据
        //自己所在团队的空缺职位
        $resJob = M('job')->field('id,name')->where('pid='.$this->userinfo['projectid'].' and num>datastate and state>0')->select();
        if ($resJob) {
            $this->assign('jobs', $resJob);
            
        }
        //flag，0可抛，1对方与自己在同一个团队，2对方已在别的团队，3自己无权限邀请，4对方账户未通过人工审核不能被邀请，5自己没有团队
        $TeamBase = new TeamBaseAction();
        $resAccount = M('account')->where('uid='.$uid)->find();
        $this->assign('account', $resAccount);
        $flag = 0;
        if ((($this->userinfo['teamid'] > 0 || $arr['teamid'] > 0) && $this->userinfo['teamid'] == $arr['teamid'])) {
            $flag = 1;
        }
        else if ($this->userinfo['teamid']<=0) {
            $flag = 5;
        }
        else if ($arr['teamid'] > 0) {
            $flag = 2;
        }
        else if (!$TeamBase->isTeamCreater($this->userinfo['teamid']) && !$TeamBase->isProjectCreater($this->userinfo['projectid'])) {
            $flag = 3;
        }
        else if ($resAccount['passcheck']==0) {
            $flag = 4;
        }
        $this->assign('iflag', $flag);
        
        //评价数据
        $tabUC = M('usercomment');
        $rateArr = $tabUC->query("SELECT ROUND(AVG(rate1)) AS avg1,ROUND(AVG(rate2)) AS avg2,ROUND(AVG(rate3)) AS avg3,ROUND(AVG(rate4)) AS avg4 FROM xia_usercomment WHERE ct=2 and uid=".$uid);
        //好评率,大于7分算好评
        $total = $tabUC->where("ct=2 and uid=".$uid)->count();
        $w1 = $tabUC->where("ct=2 and rate1>=7 and uid=".$uid)->count();
        $w2 = $tabUC->where("ct=2 and rate2>=7 and uid=".$uid)->count();
        $w3 = $tabUC->where("ct=2 and rate3>=7 and uid=".$uid)->count();
        $w4 = $tabUC->where("ct=2 and rate4>=7 and uid=".$uid)->count();
        $wellrate = floor((($w1+$w2+$w3+$w4)/($total*4))*100);
        
        $this->assign('wellrate', $wellrate);
        $this->assign('ratearr', $rateArr[0]);
    }
/*
    //用户信息
    public function intro() {
        $uid = I('uid', 0);
        $this->sidebarData($uid);

        //要求权限
        $invitAuth = 1;
        $resTeam = M('team')->where('uid=' . $this->uid . ' and state>0')->find();
        if (!$resTeam) {
            $resPrj = M('project')->where('uid=' . $this->uid)->find();
            if (!$resPrj) {
                $resAuth = M('authdispatch')->where('arid=' . $this->userinfo['role'] . ' and authid=52')->select();
                if (!$resAuth) {
                    $invitAuth = 0;
                }
            }
        }
        
        //该用户是否已有团队
        $resUserinfo = M('user_info')->where('uid=' . $uid)->find();
        if ($resUserinfo['teamid'] > 0) {
            $invitAuth = 2;
        }
        $this->assign('f_jianli', $this->priArr['f_jianli']);
        $arrjl = M('jianli')->where("uid ='" . $uid . "'")->order('id desc')->select();
        $jianli_results=array();
        if ($arrjl) {
            foreach($arrjl as $item){
                $row = $item;
                $time=explode(',',$item["time"]);
                $row["btime"]=$time[0];
                $row['etime']=$time[1];
                $jianli_results[]=$row;
            }
            $this->assign("arrjl", $jianli_results); //履历
        }
        
        
        $this->assign("userid", $uid);
        $this->assign('invitauth', $invitAuth);
        $this->assign("on", 3);
        $this->display();
    }
*/
    //用户作品
    public function works() {
        $uid = I('uid', 0);
        $this->sidebarData($uid);

        $uid = I('uid', 0);
        $this->assign('f_works', $this->priArr['f_works']);
        $worksetlist = M('workset')->where('uid='.$uid)->select();
        $worklist = M('work')->where("uid ='" . $uid . "' and wtype=1 and status=1")->order('ctime desc')->select();
        if ($worklist) {
            foreach ($worklist as $work) {
                $wsindex = 0;
                foreach ($worksetlist as $workset) {
                    if ($workset['id']==$work['wsid']) {
                        $worksetlist[$wsindex]['worklist'][] = $work;
                    }
                    $wsindex++;
                }
            }
            $this->assign("worksetlist", $worksetlist);
        }
        
        $this->assign("userid", $uid);
        $this->assign('headnav',2);
        $this->assign("on", 3);
        $this->display();
    }

    //信用评价
    public function appraise() {
        $uid = I('uid', 0);
        $this->sidebarData($uid);
        
        import('ORG.Util.Page');// 导入分页类
        $tabUC = M('usercomment');
        $field = "xia_usercomment.*, (xia_usercomment.rate1+xia_usercomment.rate2+xia_usercomment.rate3+xia_usercomment.rate4)/4 as rate,job.name as jobname,uif.nickname as author";
        $join1 = "LEFT JOIN xia_user_info uif ON uif.uid=xia_usercomment.author";
        $join2 = "LEFT JOIN xia_job job ON job.id=xia_usercomment.job";
        if ($this->userinfo['utype']==1) {
            //雇主评价
            $rateArrL = $tabUC->query("SELECT ROUND(AVG(rate1)) AS avg1,ROUND(AVG(rate2)) AS avg2,ROUND(AVG(rate3)) AS avg3,ROUND(AVG(rate4)) AS avg4 FROM xia_usercomment WHERE ct=2 and uid=".$this->uid);//雇员评价
            //好评率,大于7分算好评
            $total = $tabUC->where("ct=2 and uid=".$this->uid)->count();
            $w1 = $tabUC->where("ct=2 and rate1>=7 and uid=".$this->uid)->count();
            $w2 = $tabUC->where("ct=2 and rate2>=7 and uid=".$this->uid)->count();
            $w3 = $tabUC->where("ct=2 and rate3>=7 and uid=".$this->uid)->count();
            $w4 = $tabUC->where("ct=2 and rate4>=7 and uid=".$this->uid)->count();
            $wellrateL = floor((($w1+$w2+$w3+$w4)/($total*4))*100);
            $this->assign('wellrateL', $wellrateL);
            $this->assign('ratearrL', $rateArrL[0]);
            //评价详情
            $where = "ct=2 and status=1 and xia_usercomment.uid=".$this->uid;
            $countL = $tabUC->where($where)->count();
            $pageL = new Page($countL, 100);
            $nowPageL = isset($_GET['p'])?$_GET['p']:1;
            $commentlistL = $tabUC->field($field)->join($join1)->join($join2)->where($where)->page($nowPageL.','.$pageL->listRows)->order("xia_usercomment.endate desc")->select();
    //        dump($commentlist);
    //        exit;
            $this->assign('commentsL', $commentlistL);
            $this->assign('pageL', $pageL->show());
        }
        
        //雇员评价
        $rateArrR = $tabUC->query("SELECT ROUND(AVG(rate1)) AS avg1,ROUND(AVG(rate2)) AS avg2,ROUND(AVG(rate3)) AS avg3,ROUND(AVG(rate4)) AS avg4 FROM xia_usercomment WHERE ct=1 and uid=".$this->uid);//雇主评价
        //好评率,大于7分算好评
        $total = $tabUC->where("ct=1 and uid=".$this->uid)->count();
        $w1 = $tabUC->where("ct=1 and rate1>=7 and uid=".$this->uid)->count();
        $w2 = $tabUC->where("ct=1 and rate2>=7 and uid=".$this->uid)->count();
        $w3 = $tabUC->where("ct=1 and rate3>=7 and uid=".$this->uid)->count();
        $w4 = $tabUC->where("ct=1 and rate4>=7 and uid=".$this->uid)->count();
        $wellrateR = floor((($w1+$w2+$w3+$w4)/($total*4))*100);
        $this->assign('wellrateR', $wellrateR);
        $this->assign('ratearrR', $rateArrR[0]);

        //评价详情
        $countR = $tabUC->where($where)->count();
        $pageR = new Page($countR, 100);
        $nowPageR = isset($_GET['p'])?$_GET['p']:1;
        $where = "ct=1 and status=1 and xia_usercomment.uid=".$this->uid;
        $commentlistR = $tabUC->field($field)->join($join1)->join($join2)->where($where)->page($nowPageR.','.$pageR->listRows)->order("xia_usercomment.endate desc")->select();
//        dump($commentlist);
//        exit;
        $this->assign('commentsR', $commentlistR);
        $this->assign('pageR', $pageR->show());
        
        $this->assign('headnav',3);
        $this->assign("on", 3);
        $this->display();
    }

}

?>